﻿using LiJu.Common;
using LiJu.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LiJu
{
    public partial class ParameterManager : Form
    {


        List<string> DeleteStep = new List<string>();//删除的步骤
        List<string> DeleteTask = new List<string>();//删除的任务


        public string userID { get; set; }

        public SystemMenuRole menuRole { get; set; }

        /// <summary>
        /// 返回的参数集合
        /// </summary>
        public static List<TightenModel> tightenModels;

        public static DataTable StepDataTableData;
        public static DataTable TaskDataTableData;

        public ParameterManager()
        {
            //设置 线程可以 操作主线程UI控件  
            /*
             在多线程程序中,新创建的线程不能访问UI线程创建的窗口控件,

            这个时候如果你想要访问窗口的控件,那么你可以将窗口构造函数

            中的CheckForIllegalCrossThreadCalls设置为false.这是线程就

            能安全的访问窗体控件了.
             */
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();

            userID = ConfigurationManager.AppSettings["UserID"];
        }


        public static void InitDataTableData()
        {
            StepDataTableData = new DataTable();
            TaskDataTableData = new DataTable();
        }


        #region TCP的变量


        string ipaddress;
        int ipport;


        #endregion

        //注册控件函数
        public static void Register(Control con)
        {
            SetFlag(con);
            con.Tag = con.Width + ";" + con.Height + ";" + con.Top + ";" + con.Left;
            con.Resize += (object sender, EventArgs e) =>
            {
                Control c = (sender as Control);
                int initX = Convert.ToInt32(c.Tag.ToString().Split(';')[0]);
                int initY = Convert.ToInt32(c.Tag.ToString().Split(';')[1]);
                float x = c.Width / initX;
                float y = c.Width / initY;
                ReControlSize(x, y, c);
            };
        }

        //设置标签
        static void SetFlag(Control con)
        {
            foreach (Control c in con.Controls)
            {
                c.Tag = c.Width + ";" + c.Height + ";" + c.Top + ";" + c.Left;
                SetFlag(c);
            }
        }

        /// <summary>
        /// 刷新大小
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="obj"></param>
        static void ReControlSize(float x, float y, Control obj)
        {
            foreach (Control con in obj.Controls)
            {
                if (con.Tag == null)
                    continue;
                string[] tags = con.Tag.ToString().Split(';');
                con.Width = Convert.ToInt32(Convert.ToSingle(tags[0]) * x);
                con.Height = Convert.ToInt32(Convert.ToSingle(tags[1]) * y);
                con.Top = Convert.ToInt32(Convert.ToSingle(tags[2]) * y);
                con.Left = Convert.ToInt32(Convert.ToSingle(tags[3]) * x);
                ReControlSize(x, y, con);
            }
        }

        private void ParameterManager_Resize(object sender, EventArgs e)
        {
            //asc.controlAutoSize(this);
        }

        private void ParameterManager_SizeChanged(object sender, EventArgs e)
        {
            //asc.controlAutoSize(this);
        }

        private void ParameterManager_Load(object sender, EventArgs e)
        {

            //页面加载时控制启用功能

            SystemMenuIsFunction();


            ipaddress = "192.168.5.212";
            ipport = 5056;


            //获取参数数据
            GetParameterDataToDataGridView();

            //获取步骤参数
            GetStepDataToDataGridView();


            stepdataGridView.AllowUserToAddRows = false;


            //获取数据
            DataTable dataTables = BLL.Bll.GetTCPData();
            if (dataTables.Rows.Count > 0)
            {
                string ip = dataTables.Rows[1]["PortName"].ToString();
                string port = dataTables.Rows[1]["BaudRate"].ToString();
                ipaddress = ip;
                ipport = System.Convert.ToInt32(port);

            }
            else
            {
                ipaddress = "192.168.5.212";
                ipport = 5056;
            }

            if (Common.Batch.isMonitor == true)
            {
                ExecuteButton.Enabled = false;
            }
            else
            {
                ExecuteButton.Enabled = true;
            }
            //读取电批参数
            //GetBatchPerameterData();
        }


        /// <summary>
        /// 获取参数列表
        /// </summary>
        public void GetParameterDataToDataGridView()
        {
            DataTable paramerdata = BLL.Bll.GetParameterData();
            this.ContentColumn.DataPropertyName = "Content";
            this.AliasColumn.DataPropertyName = "Alias";
            parameterdataGridView.DataSource = paramerdata;

            parameterdataGridView.AllowUserToAddRows = false;
            parameterdataGridView.ColumnHeadersVisible = true;
            parameterdataGridView.Columns[0].ReadOnly = true;

            //parameterdataGridView = true;
        }

        /// <summary>
        /// 获取步骤列表
        /// </summary>
        public void GetStepDataToDataGridView()
        {
            //DataTable stepdata = BLL.Bll.GetStepData();
            if (parameterdataGridView.Rows.Count == 0)
            {
                return;
            }



            int index = parameterdataGridView.CurrentRow.Index;//选中任务的索引 //tasknumber - 1;
            DataTable paramerdata = BLL.Bll.QueryContentWithTaskID(parameterdataGridView.Rows[index].Cells[0].Value.ToString());
            string taskid = paramerdata.Rows[0][2].ToString(); //parameterdataGridView.Rows[index].Cells[0].Value.ToString();
            DataTable dataTabletaskid = BLL.Bll.QueryTaskIdWithStepData(taskid);

            this.IDColumn.DataPropertyName = "ID";
            this.stepColumn.DataPropertyName = "Step";
            this.lapColumn.DataPropertyName = "Lap";
            this.speedColumn.DataPropertyName = "Speed";

            this.MiniTorqueLengthColumn.DataPropertyName = "MiniTorqueLength";
            this.MaxTorqueLengthColumn.DataPropertyName = "MaxTorqueLength";
            this.SafeTorqueLengthColumn.DataPropertyName = "SafeTorqueLength";

            this.TargetTorqueLengthColumn.DataPropertyName = "TargetTorqueLength";
            this.MiniAngleColumn.DataPropertyName = "MiniAngle";
            this.MaxAngleColumn.DataPropertyName = "MaxAngle";

            this.SafeAngleColumn.DataPropertyName = "SafeAngle";
            this.TargetAngleColumn.DataPropertyName = "TargetAngle";

            this.AnglethresholdColumn.DataPropertyName = "Anglethreshold";

            this.StepTypeColumn.DataPropertyName = "StepType";
            this.TighteningtypeColumn.DataPropertyName = "TighteningType";

            stepdataGridView.DataSource = dataTabletaskid;
            //stepdataGridView.DataSource = stepdata;
            stepdataGridView.Columns["stepColumn"].ReadOnly = true;
            stepdataGridView.Columns["lapColumn"].ReadOnly = true;

            //stepdataGridView.Rows[rowsindex].Cells[columsindex].ReadOnly = true;
            for (int i = 0; i < dataTabletaskid.Rows.Count; i++)
            {
                //2,7
                if (dataTabletaskid.Rows[i][13].ToString() == "不可用")
                {
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;
                    //stepdataGridView.Rows[i].Cells["StepTypeColumn"].ReadOnly = true;
                    //stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].ReadOnly = true;
                }
            }

            stepdataGridView.DataSource = dataTabletaskid;


            //CalLap();
        }

        /// <summary>
        /// 转成16进制
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string ConvertStringToHex(string input)
        {
            byte[] byteArray = Encoding.UTF8.GetBytes(input);
            string hexString = BitConverter.ToString(byteArray);
            return hexString.Replace("-", "");
        }

        /// <summary>
        /// 间隔N个字符插入字符
        /// </summary>
        /// <param name="input">输入字符</param>
        /// <param name="interval">几个间隔数</param>
        /// <param name="value">插入符号</param>
        /// <returns></returns>
        public string InsertFormat(string input, int interval, string value)
        {
            for (int i = interval; i < input.Length; i += interval + 1)
            {
                input = input.Insert(i, value);
            }
            return input;
        }

        /// <summary>
        /// 握手
        /// </summary>
        public void GetHand()
        {
            Common.Batch.SendOut("30 30 32 30 30 30 30 31 20 20 20 20 20 20 20 20 20 20 20 20 00");//握手
        }

        /// <summary>
        /// 使能
        /// </summary>
        public void Enable()
        {
            Common.Batch.SendOut("30 30 32 30 30 30 34 33 20 20 20 20 20 20 20 20 20 20 20 20 00");//使能
        }

        /// <summary>
        /// 不使能
        /// </summary>
        public void DisEnable()
        {
            Common.Batch.SendOut("30 30 32 30 30 30 34 32 20 20 20 20 20 20 20 20 20 20 20 20 00");//不使能
        }

        /// <summary>
        /// 订阅结果
        /// </summary>
        public void SetResult()
        {
            Common.Batch.SendOut("30 30 32 30 30 30 36 30 20 20 20 20 20 20 20 20 20 20 20 20 00");//订阅结果
        }

        /// <summary>
        /// 步骤订阅(00207402)
        /// PHASES RESULTS SUBSCRIBE
        /// </summary>
        public void SetPhasesSubscribe()
        {
            Common.Batch.SendOut("30 30 32 30 37 34 30 32 20 20 20 20 20 20 20 20 20 20 20 20 00");
        }

        /// <summary>
        /// 曲线订阅(00207408001)
        /// LAST CURVE SUBSCRIBE
        /// </summary>
        public void SetLastCurve()
        {
            Common.Batch.SendOut("30 30 32 30 37 34 30 38 20 20 20 20 20 20 20 20 20 20 20 20 00");
        }

        /// <summary>
        /// 读取程序参数
        /// </summary>
        public void GetParameter()
        {
            string programnumber = "30 30 31";
            string stepnumber = "30 32";
            string messae = "30 30 32 39 37 34 31 32 30 30 31 20 20 20 20 20 20 20 20 20 30 31 " + programnumber + " 30 32 " + stepnumber + " 00";
            //SendOut(messae);
            //Common.Batch.SendOut("30 30 32 39 37 34 31 32 30 30 31 20 20 20 20 20 20 20 20 20 30 31 30 30 31 30 32 30 32 00");//读取程序参数
            Common.Batch.SendOut(messae);
        }

        /// <summary>
        /// 调用程序
        /// </summary>
        /// <param name="tasknumber">任务号3位数不够补零</param>
        /// <param name="stepnumber">步骤号两位数不够补零</param>
        public void UseProgramIndexAndStepIndex(int tasknumber, int stepnumber)
        {
            //任务号转为16进制字符串
            string strtasknumber = tasknumber.ToString().PadLeft(3, '0');

            string tasknumberhexstring = ConvertStringToHex(strtasknumber);

            string tasknumberresult = InsertFormat(tasknumberhexstring, 2, " ") + "";

            //步骤号转为16进制字符串
            string strstepnumber = stepnumber.ToString().PadLeft(2, '0');

            string stepnumberhexstring = ConvertStringToHex(strstepnumber);

            string stepnumberresult = InsertFormat(stepnumberhexstring, 2, " ") + "";


            Common.Batch.SendOut("30 30 32 39 37 34 31 32 30 30 31 20 20 20 20 20 20 20 20 20 30 31 " + tasknumberresult + " 30 32 " + stepnumberresult + " 00");//
        }

        /// <summary>
        /// 16进制转字符串
        /// </summary>
        /// <param name="hex"></param>
        /// <returns></returns>
        public string HexToString(string hex)
        {
            // 将16进制字符串转换为字节数组
            byte[] bytes = new byte[hex.Length / 2];
            for (int i = 0; i < bytes.Length; i++)
            {
                bytes[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
            }

            // 使用UTF8编码将字节数组转换为字符串
            return Encoding.UTF8.GetString(bytes);
        }

        /// <summary>
        /// 连接TCP
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TCPConnectionbutton_Click(object sender, EventArgs e)
        {
            Common.Batch.Connection(ipaddress, ipport.ToString());
            GetHand();//握手指令
            Thread.Sleep(10);
            Common.Batch.AutoSend();//心跳发送
            SetPhasesSubscribe();
            SetLastCurve();
            Enable();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Common.Batch.isMonitor == false)
            {
                Common.Batch.Connection(ipaddress, ipport.ToString());
                Common.Batch.GetHand();//握手指令
                Common.Batch.SetResult();
                Thread.Sleep(10);
                Common.Batch.AutoSend();//心跳发送
            }
            string pattern = @"\d+";



            int index = parameterdataGridView.CurrentRow.Index;//选中任务的索引
            var a = parameterdataGridView.Rows[index].Cells[0].Value;
            int number = -1;
            MatchCollection matches = Regex.Matches(a.ToString(), pattern);
            foreach (Match match in matches)
            {
                Console.WriteLine(match.Value);
                number = System.Convert.ToInt32(match.Value);
                //contentlistint.Add(number);
            }
            Common.Batch.UseProgramIndex(number);
            Common.Batch.Enable();
        }

        List<int> tasklist = new List<int>();
        List<string> taskstr = new List<string>();

        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddTaskbutton_Click(object sender, EventArgs e)
        {
            string pattern = @"\d+";

            List<string> contentlist = new List<string>();
            List<int> contentlistint = new List<int>();
            DataTable dataTable = (DataTable)parameterdataGridView.DataSource; //BLL.Bll.GetParameterData();

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                contentlist.Add(dataTable.Rows[i][0].ToString());
                //提取数字
                MatchCollection matches = Regex.Matches(dataTable.Rows[i][0].ToString(), pattern);
                foreach (Match match in matches)
                {
                    Console.WriteLine(match.Value);
                    int number = System.Convert.ToInt32(match.Value);
                    contentlistint.Add(number);
                }
            }

            if (contentlistint.Count > 0)
            {
                var max = contentlistint.Max();
                if (max >= 50)
                {
                    MessageBox.Show("任务最多五十个！");
                    return;
                }
                int newnumber = max + 1;
                string newcontent = "任务" + newnumber;
                tasklist.Add(newnumber);
                dataTable.Rows.Add(newcontent);
                //BLL.Bll.InsertParameterData(newcontent, newnumber.ToString());
                taskstr.Add(newcontent);
            }
            else
            {
                //BLL.Bll.InsertParameterData("任务1", "1");
                dataTable.Rows.Add("任务1");
                tasklist.Add(1);
                taskstr.Add("任务1");
            }
            parameterdataGridView.DataSource = dataTable;
            //GetParameterDataToDataGridView();
        }

        private void parameterdataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            GetStepData();
        }

        /// <summary>
        /// 获取步骤函数
        /// </summary>
        public void GetStepData()
        {
            int index = parameterdataGridView.CurrentRow.Index;//选中任务的索引 //tasknumber - 1;
            DataTable dataTable = (DataTable)parameterdataGridView.DataSource;
            var abc = parameterdataGridView.Rows[index].Cells[0].Value.ToString();
            DataTable paramerdata = BLL.Bll.QueryContentWithTaskID(parameterdataGridView.Rows[index].Cells[0].Value.ToString());
            if (paramerdata.Rows.Count == 0)
            {
                return;
            }
            string taskid = paramerdata.Rows[0][2].ToString(); //parameterdataGridView.Rows[index].Cells[0].Value.ToString();
            DataTable dataTabletaskid = BLL.Bll.QueryTaskIdWithStepData(taskid);
            //int taskid = System.Convert.ToInt32(dataTabletaskid.Rows[0][2]);
            stepdataGridView.DataSource = dataTabletaskid;
            //UpdateGridViewCellBackGround();
        }


        private void button2_Click(object sender, EventArgs e)
        {
            //Common.Batch.Enable();
            //LiJu.Common.Batch.TCPConnection();
            Common.Batch.Enable();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Common.Batch.DisEnable();
        }

        /// <summary>
        /// 保存函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveDatabutton_Click(object sender, EventArgs e)
        {
            SaveDataAndUseProgram(false);
        }




        /// <summary>
        /// 保存参数并且同步至电批设备
        /// </summary>
        private void SaveDataAndUseProgram(bool IsSave)
        {
            Common.Batch.stepidlist = new List<string>();//任务号，步骤号

            Common.Batch.taskidlist = new List<string>();

            int insertexecuteresult = -1;
            int updateexecuteresult = -1;

            DataTable NewdataTable = (DataTable)stepdataGridView.DataSource;


            if (NewdataTable != null && IsSave)
            {
                for (int i = 0; i < NewdataTable.Rows.Count; i++)
                {

                    int id = Convert.ToInt32(NewdataTable.Rows[i]["ID"].ToString());
                    string Step = NewdataTable.Rows[i]["Step"].ToString();
                    string Lap = NewdataTable.Rows[i]["Lap"].ToString();
                    string Speed = NewdataTable.Rows[i]["Speed"].ToString();
                    string MiniTorqueLength = NewdataTable.Rows[i]["MiniTorqueLength"].ToString();
                    string MaxTorqueLength = NewdataTable.Rows[i]["MaxTorqueLength"].ToString();
                    string SafeTorqueLength = NewdataTable.Rows[i]["SafeTorqueLength"].ToString();
                    string Anglethreshold = NewdataTable.Rows[i]["Anglethreshold"].ToString();
                    string TargetTorqueLength = NewdataTable.Rows[i]["TargetTorqueLength"].ToString();
                    string MiniAngle = NewdataTable.Rows[i]["MiniAngle"].ToString();
                    string MaxAngle = NewdataTable.Rows[i]["MaxAngle"].ToString();
                    string SafeAngle = NewdataTable.Rows[i]["SafeAngle"].ToString();
                    string TargetAngle = NewdataTable.Rows[i]["TargetAngle"].ToString();

                    updateexecuteresult = BLL.Bll.UpdateStepData(id, Step, Lap, Speed, MiniTorqueLength, MaxTorqueLength, SafeTorqueLength, Anglethreshold, TargetTorqueLength, MiniAngle, MaxAngle, SafeAngle, TargetAngle);

                }
                if (DeleteStep.Count > 0)
                {
                    int result = -1;
                    for (int i = 0; i < DeleteStep.Count; i++)
                    {
                        result = BLL.Bll.DeleteStepByTaskIdData(DeleteStep[i], DeleteTask[i]);

                    }
                    if (result > 0)
                    {
                        //MessageBox.Show("成功");
                    }
                }



                if (insertexecuteresult > 0 || updateexecuteresult > 0)
                {
                    MessageBox.Show("保存数据成功！");
                }
            }


            //UpdateStepData
            //如果id存在则更新
            //否则添加数据

            #region


            //更新注释,选中那个改哪个
            {
                int indexss = parameterdataGridView.CurrentRow.Index;
                var taskcontents = parameterdataGridView.Rows[indexss].Cells[0].Value.ToString();
                var aliascontents = parameterdataGridView.Rows[indexss].Cells[1].Value.ToString();
                var taskidstr = taskcontents.Replace("任务", "");
                var taskids = Convert.ToInt32(taskidstr);
                var updatealiasresult = BLL.Bll.UpdateParameterAliasData(taskids, aliascontents);
                if (updatealiasresult > 0)
                {
                    MessageBox.Show("更新任务数据成功！");
                }
            }
            #endregion
            string pattern = @"\d+";
            int index = parameterdataGridView.CurrentRow.Index;//选中任务的索引
            var currindex = parameterdataGridView.Rows[index].Cells[0].Value;
            int number = -1;
            MatchCollection matches = Regex.Matches(currindex.ToString(), pattern);
            foreach (Match match in matches)
            {
                Console.WriteLine(match.Value);
                number = System.Convert.ToInt32(match.Value);
                //contentlistint.Add(number);
            }
            Common.Batch.UseProgramIndex(number);
        }


        private void ExecuteButton_Click(object sender, EventArgs e)
        {

            if (Common.Batch.isMonitor == false)
            {
                Common.Batch.Connection(ipaddress, ipport.ToString());
                //

                Common.Batch.GetHand();//握手指令
                Common.Batch.SetResult();
                Thread.Sleep(10);
                Common.Batch.AutoSend();//心跳发送
            }
            string pattern = @"\d+";

            if (parameterdataGridView.Rows.Count == 0)
            {
                return;
            }

            int index = parameterdataGridView.CurrentRow.Index;//选中任务的索引
            var currindex = parameterdataGridView.Rows[index].Cells[0].Value;
            int number = -1;
            MatchCollection matches = Regex.Matches(currindex.ToString(), pattern);
            foreach (Match match in matches)
            {
                Console.WriteLine(match.Value);
                number = System.Convert.ToInt32(match.Value);
                //contentlistint.Add(number);
            }
            //Common.Batch.InvokeTask(number);
            Common.Batch.UseProgramIndex(number);
            Common.Batch.Enable();

            //string content=parameterdataGridView.Rows[index].Cells[0].Value.ToString();
            //DataTable dataTabletaskid = BLL.Bll.QueryContentWithTaskID(content);
            //int taskid = System.Convert.ToInt32(dataTabletaskid.Rows[0][2]);
            //DataTable dataTable = BLL.Bll.GetTaskWithStep(taskid);
            //if (dataTable.Rows.Count>0)
            //{

            //}
        }

        private void stepdataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //CalLap();
        }

        private void stepdataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            //CalLap();
        }

        private void stepdataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int index = stepdataGridView.CurrentRow.Index;
            int columnindex = stepdataGridView.CurrentCell.ColumnIndex;
            //CalLap();
            DataTable dataTable = (DataTable)stepdataGridView.DataSource;
            string result = dataTable.Rows[index][13].ToString();
            List<int> vs = new List<int>();
            vs.Add(0);
            vs.Add(1);
            vs.Add(3);
            vs.Add(4);
            vs.Add(5);
            vs.Add(6);
            vs.Add(8);
            vs.Add(9);
            vs.Add(10);
            vs.Add(11);

            if (result == "不可用")
            {
                var exits = vs.Where(x => x.Equals(columnindex)).ToList();
                if (exits.Count > 0)
                {
                    MessageBox.Show("不可修改！");
                    e.Cancel = true;
                    return;
                }
                //if (index!=2||index!=7)
                //{
                //    MessageBox.Show("不可修改！");
                //    e.Cancel = true;
                //    return;
                //}
            }

        }

        private void stepdataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //CalLap();
        }

        private void stepdataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            //CalLap();
        }

        private void stepdataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            //CalLap();
        }


        /// <summary>
        /// 页面功能加载
        /// </summary>
        /// <param name="userID">用户ID</param>
        public void SystemMenuIsFunction()
        {



            GetBatchData.Enabled = false;
            SaveDatabutton.Enabled = false;
            ExecuteButton.Enabled = false;

            //获取当前页面功能
            menuRole = PageDataDto.SystemMenuRoleInfo();

            if (menuRole.Parm_Load || userID == "admin")
            {
                GetBatchData.Enabled = true;
            }
            if (menuRole.Parm_Save || userID == "admin")
            {
                SaveDatabutton.Enabled = true;
            }
            if (menuRole.Parm_Exec || userID == "admin")
            {
                ExecuteButton.Enabled = true;
            }


        }



        private void button1_Click_1(object sender, EventArgs e)
        {



        }


        private void stepdataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            //判定当前用户是否拥有设置权限
            if (menuRole.Parm_Setting || userID == "admin")
            {

                int rowIndex = stepdataGridView.CurrentRow.Index;

                // 从DataGridView的DataSource获取DataTable

                DataTable dataTable = stepdataGridView.DataSource as DataTable;

                // 确保dataSource确实是DataTable类型才继续
                if (dataTable != null)
                {

                    DataRow dataRow = dataTable.Rows[rowIndex];

                    //获取当前选择行数据 
                    StepModel stepModel = new StepModel()
                    {
                        Step = Convert.ToString(dataRow["Step"]),
                        Lap = Convert.ToString(dataRow["Lap"]),
                        Speed = Convert.ToString(dataRow["Speed"]),
                        MiniTorqueLength = Convert.ToString(dataRow["MiniTorqueLength"]),
                        MaxTorqueLength = Convert.ToString(dataRow["MaxTorqueLength"]),
                        SafeTorqueLength = Convert.ToString(dataRow["SafeTorqueLength"]),
                        Anglethreshold = Convert.ToString(dataRow["Anglethreshold"]),
                        TargetTorqueLength = Convert.ToString(dataRow["TargetTorqueLength"]),
                        MiniAngle = Convert.ToString(dataRow["MiniAngle"]),
                        MaxAngle = Convert.ToString(dataRow["MaxAngle"]),
                        SafeAngle = Convert.ToString(dataRow["SafeAngle"]),
                        TargetAngle = Convert.ToString(dataRow["TargetAngle"]),
                        StepType = Convert.ToString(dataRow["StepType"]),
                        TighteningType = Convert.ToString(dataRow["TighteningType"])

                    };

                    //调用参数设置页面，并传递参数
                    ParmeterEdit parmeterEdit = new ParmeterEdit()
                    {
                        stepModel = stepModel
                    };

                    parmeterEdit.ShowDialog();

                    //取得修改后数据
                    if (parmeterEdit.stepModel != null)
                    {

                        stepdataGridView.Rows[e.RowIndex].Cells["lapColumn"].Value = parmeterEdit.stepModel.Lap;
                        stepdataGridView.Rows[e.RowIndex].Cells["speedColumn"].Value = parmeterEdit.stepModel.Speed;
                        stepdataGridView.Rows[e.RowIndex].Cells["MiniTorqueLengthColumn"].Value = parmeterEdit.stepModel.MiniTorqueLength;
                        stepdataGridView.Rows[e.RowIndex].Cells["MaxTorqueLengthColumn"].Value = parmeterEdit.stepModel.MaxTorqueLength;
                        stepdataGridView.Rows[e.RowIndex].Cells["SafeTorqueLengthColumn"].Value = parmeterEdit.stepModel.SafeTorqueLength;
                        stepdataGridView.Rows[e.RowIndex].Cells["AnglethresholdColumn"].Value = parmeterEdit.stepModel.Anglethreshold;
                        stepdataGridView.Rows[e.RowIndex].Cells["TargetTorqueLengthColumn"].Value = parmeterEdit.stepModel.TargetTorqueLength;
                        stepdataGridView.Rows[e.RowIndex].Cells["MiniAngleColumn"].Value = parmeterEdit.stepModel.MiniAngle;
                        stepdataGridView.Rows[e.RowIndex].Cells["MaxAngleColumn"].Value = parmeterEdit.stepModel.MaxAngle;
                        stepdataGridView.Rows[e.RowIndex].Cells["SafeAngleColumn"].Value = parmeterEdit.stepModel.SafeAngle;
                        stepdataGridView.Rows[e.RowIndex].Cells["TargetAngleColumn"].Value = parmeterEdit.stepModel.TargetAngle;

                        //保存
                        SaveDataAndUseProgram(parmeterEdit.IsSave);
                    }

                }
            }


        }

        private void GetBatchData_Click(object sender, EventArgs e)
        {
            //Task.Run(()=>
            //{
            Common.Batch.stepidlist = new List<string>();//任务号，步骤号
            Common.Batch.taskidlist = new List<string>();
            //BLL.Bll.TruncateParameterAndStep();
            Common.Batch.NewGetParameter();
            //获取参数数据
            GetParameterDataToDataGridView();

            //获取步骤参数
            GetStepDataToDataGridView();

            stepdataGridView.AllowUserToAddRows = false;
            //});

        }

        private void stepdataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            for (int i = 0; i < stepdataGridView.Rows.Count; i++)
            {
                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "快速下旋")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    try
                    {
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                        {
                            stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                        {
                            stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value.ToString()))
                        {
                            stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                        {
                            stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                        {

                            stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                        {

                            stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                        {
                            stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                        {
                            stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                        }
                        if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                        {
                            stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                        }

                    }
                    catch (Exception ex)
                    {

                        Debug.WriteLine(ex.Message);
                    }


                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;


                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "最终拧紧" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "扭矩+角度")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "最终拧紧" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "角度+扭矩")
                {
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }

                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "最终拧紧" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "扭矩")
                {

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }


                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "最终拧紧" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "无")
                {

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;


                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }


                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "最终拧紧" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "落座检测")
                {

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }


                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "最终拧紧" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "落座后检测")
                {

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }


                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                }

                //寻帽
                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "寻帽")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }

                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "反转" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "扭矩+角度")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }

                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "反转" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "角度+扭矩")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;


                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }

                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "反转" && stepdataGridView.Rows[i].Cells["TighteningtypeColumn"].Value.ToString() == "扭矩")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }

                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "不合格动作")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["speedColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["speedColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "等待同步")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["speedColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["speedColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "跳转")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["speedColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["speedColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }
                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "角度控制快速下旋")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Value = "";
                    }

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Value = "";
                    }

                }

                if (stepdataGridView.Rows[i].Cells["StepTypeColumn"].Value.ToString() == "摩檫力扭矩监控")
                {
                    stepdataGridView.Rows[i].Cells["lapColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["speedColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].ReadOnly = true;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].ReadOnly = true;

                    stepdataGridView.Rows[i].Cells["lapColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["speedColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Style.BackColor = Color.LightGray;
                    stepdataGridView.Rows[i].Cells["TargetAngleColumn"].Style.BackColor = Color.LightGray;

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["lapColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["lapColumn"].Value = "";
                    }

                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["AnglethresholdColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["TargetTorqueLengthColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value.ToString()))
                    {

                        stepdataGridView.Rows[i].Cells["MiniAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["MaxAngleColumn"].Value = "";
                    }
                    if (!string.IsNullOrEmpty(stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value.ToString()))
                    {
                        stepdataGridView.Rows[i].Cells["SafeAngleColumn"].Value = "";
                    }


                }
            }

        }
    }
}
